package ua.org.enginer.entities {
	
	
	[Bindable]
	public class File  {
		
		public var owner:Object
		
		public var id:Number
		public var created_time:Date
		public var owner_id:Number;
		public var owner_type:String;
		public var name:String;
		public var size:int;
		public var type:String;
		public var path:String;
		
		
		public function File(o:Object=null):void {
			applyData(o)
		}
		
		public function toString():String {
			return name
		}
		
		public function get label():String {
			return toString()
		}
		
		public function applyData(data:Object):void {
			for (var p:String in data) {
				if (p == 'id' && !data[p]) continue;
				if (!data[p] || data[p] == "null") {
					if (this[p] is String) 		this[p] =  ''
					else if (this[p] is Number) this[p] =  0
					continue
				}
				
				// время храниться в цифровом виде (милисекунды)
				if (p.indexOf("_time") > 0 || p.indexOf("_date") > 0) {
					this[p] = new Date(Number(data[p]))
				}else
					this[p] = data[p]
			}
		}
	}
}